#include "MessageDispatcher.h"


MessageDispatcher::MessageDispatcher(void)
{
}


MessageDispatcher::~MessageDispatcher(void)
{
}

MessageDispatcher* MessageDispatcher::Instance()
{
	static MessageDispatcher* m_instance = NULL;
	if(!m_instance)
		m_instance = new MessageDispatcher();
	return m_instance;
}

void MessageDispatcher::DispatchMouseMessage( MouseMsg msg,LPARAM lParam )
{
	switch(msg)
	{
	case MMsg_Move:
		int x,y;
		x = LOWORD(lParam);
		y = HIWORD(lParam);
		MouseSubject::Instance()->SetCurrentPoint(x,y);
		MouseSubject::Instance()->MouseNotify(msg);
		MouseSubject::Instance()->UpdateOldPoint();
		break;

	case MMsg_LeftButtonDown:
	case MMsg_LeftButtonUp:
	case MMsg_RightButtonDown:
	case MMsg_RightButtonUp:
		MouseSubject::Instance()->MouseNotify(msg);
		break;
	}
}

void MessageDispatcher::DispatchKeyboardMessage( WPARAM wParam )
{
	switch( wParam )
	{
	case 'w':
	case 'W':
		KeyboardSubject::Instance()->KeyboardNotify(KMsg_W);
		break;
	case 'a':
	case 'A':
		KeyboardSubject::Instance()->KeyboardNotify(KMsg_A);
		break;
	case 's':
	case 'S':
		KeyboardSubject::Instance()->KeyboardNotify(KMsg_S);
		break;
	case 'd':
	case 'D':
		KeyboardSubject::Instance()->KeyboardNotify(KMsg_D);
		break;
	}
}

void MessageDispatcher::DispatchKeyboardDownMessage()
{
	if(GetAsyncKeyState('A') & 0x8000)
		KeyboardSubject::Instance()->KeyboardNotify(KMsg_A_DOWN);

	if(GetAsyncKeyState('D') & 0x8000)
		KeyboardSubject::Instance()->KeyboardNotify(KMsg_D_DOWN);

	if(GetAsyncKeyState('W') & 0x8000)
		KeyboardSubject::Instance()->KeyboardNotify(KMsg_W_DOWN);

	if(GetAsyncKeyState('S') & 0x8000)
		KeyboardSubject::Instance()->KeyboardNotify(KMsg_S_DOWN);
}
